import {reqDetailData} from '@/api/index'

const state = {
    detailData : {}
}

const getters = {
    categoryView(state){
        return state.detailData.categoryView || {}
    },
    skuInfo(state){
        return state.detailData.skuInfo || {}
    },
    spuSaleAttrList(state){
        return state.detailData.spuSaleAttrList || []
    }
}

const actions = {
    async getDetailData({commit},id){
        const result = await reqDetailData(id)
        if(result.code === 200){
            commit('UPDATE_DETAIL_DATA',result.data)
        }else{
            console.log('请求detail数据失败',result.message);
        }
    }
}

const mutations = {
    UPDATE_DETAIL_DATA(state,payload){
        state.detailData = payload        
    }
}

export default {
    namespaced:true,
    state,
    getters,
    actions,
    mutations
}

